/*----------------------------------------------------------------------
  - File name      : dev_kscan.c
  - Author         : Quark Team
  - Update date    : 2020-10-30                   
  -	Copyright      : Gevico Electronic studio   
  - Module comments: Key scan module.
-----------------------------------------------------------------------*/
/*-----------------------------------------------------------------------
|                               INCLUDES                                |
-----------------------------------------------------------------------*/
#include "dev_kscan.h"
/*-----------------------------------------------------------------------
|                                 DATA                                  |
-----------------------------------------------------------------------*/
/* None */
/*-----------------------------------------------------------------------
|                               FUNCTION                                |
-----------------------------------------------------------------------*/

/*--------------------------------------------------------
| @Description: Key Scan init function                   |
| @param      : None                                     |
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE Key_GPIO_Init(void)
{
	P1_MODE_IN_FLOATING(Pin_1);

	/* Add new gpio configuriton */
	
	return FSC_SUCCESS;
}

/*--------------------------------------------------------
| @Description: Key Scan P0 function                     |
| @param      : KEY_STATE State,uint8 *BackDat           |  
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE Key_Scan_P0_One(KEY_STATE State,uint8 *BackDat)
{
	static uint8 Trg,Cont;
	uint8 RDat;
	RDat = P0 ^ 0xff;
	Trg = (RDat ^ Cont) & RDat;
	Cont = RDat;
	if (State == KEY_State_One){
		*BackDat = Trg;  return FSC_SUCCESS;}
	else if(State == KEY_State_Mul){
		*BackDat = Cont; return FSC_SUCCESS;}
	return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: Key Scan P1 function                     |
| @param      : KEY_STATE State,uint8 *BackDat           |  
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE Key_Scan_P1_One(KEY_STATE State,uint8 *BackDat)
{
	static uint8 Trg,Cont;
	uint8 RDat;
	RDat = P1 ^ 0xff;
	Trg = (RDat ^ Cont) & RDat;
	Cont = RDat;
	if (State == KEY_State_One) {
		*BackDat = Trg;  return FSC_SUCCESS;}
	else if(State == KEY_State_Mul) {
		*BackDat = Cont; return FSC_SUCCESS;}
	return FSC_FAIL;
}


/*--------------------------------------------------------
| @Description: Key Scan P2 function                     |
| @param      : KEY_STATE State,uint8 *BackDat           |  
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE Key_Scan_P2_One(KEY_STATE State,uint8 *BackDat)
{
	static uint8 Trg,Cont;
	uint8 RDat;
	RDat = P2 ^ 0xff;
	Trg = (RDat ^ Cont) & RDat;
	Cont = RDat;
	if (State == KEY_State_One) {
		*BackDat = Trg;  return FSC_SUCCESS;}
	else if(State == KEY_State_Mul) {
		*BackDat = Cont; return FSC_SUCCESS;}
	return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: Key Scan P3 function                     |
| @param      : KEY_STATE State,uint8 *BackDat           |  
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE Key_Scan_P3_One(KEY_STATE State,uint8 *BackDat)
{
	static uint8 Trg,Cont;
	uint8 RDat;
	RDat = P3 ^ 0xff;
	Trg = (RDat ^ Cont) & RDat;
	Cont = RDat;
	if (State == KEY_State_One) {
		*BackDat = Trg;  return FSC_SUCCESS;}
	else if(State == KEY_State_Mul) {
		*BackDat = Cont; return FSC_SUCCESS;}
	return FSC_FAIL;
}


/*--------------------------------------------------------
| @Description: Key Scan P4 function                     |
| @param      : KEY_STATE State,uint8 *BackDat           |  
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE Key_Scan_P4_One(KEY_STATE State,uint8 *BackDat)
{
	static uint8 Trg,Cont;
	uint8 RDat;
	RDat = P4 ^ 0xff;
	Trg = (RDat ^ Cont) & RDat;
	Cont = RDat;
	if (State == KEY_State_One) {
		*BackDat = Trg;  return FSC_SUCCESS;}
	else if(State == KEY_State_Mul) {
		*BackDat = Cont; return FSC_SUCCESS;}
	return FSC_FAIL;
}


/*--------------------------------------------------------
| @Description: Key Scan P5 function                     |
| @param      : KEY_STATE State,uint8 *BackDat           |  
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE Key_Scan_P5_One(KEY_STATE State,uint8 *BackDat)
{
	static uint8 Trg,Cont;
	uint8 RDat;
	RDat = P5 ^ 0xff;
	Trg = (RDat ^ Cont) & RDat;
	Cont = RDat;
	if (State == KEY_State_One) {
		*BackDat = Trg;  return FSC_SUCCESS;}
	else if(State == KEY_State_Mul) {
		*BackDat = Cont; return FSC_SUCCESS;}
	return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: Key Scan P6 function                     |
| @param      : KEY_STATE State,uint8 *BackDat           |  
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE Key_Scan_P6_One(KEY_STATE State,uint8 *BackDat)
{
	static uint8 Trg,Cont;
	uint8 RDat;
	RDat = P6 ^ 0xff;
	Trg = (RDat ^ Cont) & RDat;
	Cont = RDat;
	if (State == KEY_State_One) {
		*BackDat = Trg;  return FSC_SUCCESS;}
	else if(State == KEY_State_Mul) {
		*BackDat = Cont; return FSC_SUCCESS;}
	return FSC_FAIL;
}

/*--------------------------------------------------------
| @Description: Key Scan P7 function                     |
| @param      : KEY_STATE State,uint8 *BackDat           |  
| @return     : FSCSTATE : Success / Fail                |
--------------------------------------------------------*/

FSCSTATE Key_Scan_P7_One(KEY_STATE State,uint8 *BackDat)
{
	static uint8 Trg,Cont;
	uint8 RDat;
	RDat = P7 ^ 0xff;
	Trg = (RDat ^ Cont) & RDat;
	Cont = RDat;
	if (State == KEY_State_One) {
		*BackDat = Trg;  return FSC_SUCCESS;}
	else if(State == KEY_State_Mul) {
		*BackDat = Cont; return FSC_SUCCESS;}
	return FSC_FAIL;
}


/*-----------------------------------------------------------------------
|          END OF FLIE        (C) COPYRIGHT Gevico Electronics          | 
-----------------------------------------------------------------------*/



